﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TXTD.Admin.Data.Entitys.System;
using TXTD.Admin.Interface.System;
using TXTD.Admin.Model.Core;
using TXTD.Admin.Model.Modules.System;
using TXTD.Admin.Service.Utilitys.Jwt;

namespace TXTD.Admin.WebApi.Modules.System
{
    //[Authorize]
    [ApiController]
    [Route("api/System/[controller]")]
    public class SysUserController : ControllerBase
    {
        private ISysUserService userService;
        private JwtHelper jwtHelper;
        public SysUserController(ISysUserService _userService, JwtHelper _jwtHelper)
        {
            userService = _userService;
            jwtHelper = _jwtHelper;
        }
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetPageList")]
        public ResultModel GetPageList([FromQuery] SysUser model)
        {
            return ResultModel.ResultBy(userService.GetPageList(model)) ;
        }
        [HttpPost("Add")]
        public ResultModel Add(SysUser model)
        {
            return ResultModel.ResultByCount(userService.Add(model));
        }
        [HttpPost("Update")]
        public ResultModel Update(SysUser model)
        {
            return ResultModel.ResultByCount(userService.Update(model));
        }
        [HttpPost("Delete")]
        public ResultModel Delete(string id)
        {
            return ResultModel.ResultByCount(userService.DeleteById(id));
        }
        [HttpPost("UpdateEnabled")]
        public ResultModel UpdateEnabled(SysUser model)
        {
            return ResultModel.ResultByCount(userService.UpdateEnabled(model));
        }
        [HttpPost("ResetPassword")]
        public ResultModel ResetPassword(SysUser model)
        {
            return ResultModel.ResultByCount(userService.ResetPassword(model));
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <returns></returns>
        [HttpPost("Login")]
        [AllowAnonymous]
        public ResultModel Login(LoginModel user)
        {
            return userService.Login(user);
        }
        /// <summary>
        /// 刷新token
        /// </summary>
        /// <returns></returns>
        [HttpPost("RefreshToken")]
        [AllowAnonymous]
        public ResultModel RefreshToken(ResultTokenModel resultToken)
        {
            return ResultModel.ResultBy(userService.RefreshToken(resultToken));
        }
        /// <summary>
        /// 获取登录用户信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetUserInfo")]
        public ResultModel GetUserInfo()
        {
            return ResultModel.ResultBy(userService.GetUserInfo());
        }
    }
}
